package com.wyx.Dao.test;

import com.wyx.Dao.dao.ActorDao;
import com.wyx.Dao.dao.BasicDao;
import com.wyx.Dao.dao.GoodsDao;
import com.wyx.Dao.domain.Actor;
import com.wyx.Dao.domain.Goods;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class testDao {

    @Test
    //测试ActorDao,对actor表进行crud操作
    public void testActorDao() {
        ActorDao actorDao = new ActorDao();
        //查询多行多列数据
        List<Actor> actors = actorDao.queryMulti("select * from actor", Actor.class);
        for (Actor actor :actors) {
            System.out.println(actor);
        }


        System.out.println("====================");
        //查询单行多列数据
        Actor actor = actorDao.querySingle("select * from actor where id = ?", Actor.class, 1);
        System.out.println(actor);

        System.out.println("=======================");
        //查询单个数据
        Object o = actorDao.queryScalar("select name from actor where id = ?", 2);
        System.out.println(o);


        //增
        int update = actorDao.update("insert into actor values(null,?,?,?,?)", "林俊杰", "男", "1986-02-12", "18648612");
        System.out.println(update > 0 ? "成功" : "未修改表");

        //改
        int update1 = actorDao.update("update actor set name = ? where id = ?", "周杰伦", 5);
        System.out.println(update1 > 0 ? "成功" : "未修改表");

    }



    @Test
    //测试GoodsDao
    public void testGoodsDao(){
        GoodsDao goodsDao = new GoodsDao();
        List<Goods> goods = goodsDao.queryMulti("select * from Goods", Goods.class);
        for (Goods goods1 :goods) {
            System.out.println(goods1);
        }

        Goods goods1 = goodsDao.querySingle("select goods_name from goods where id = ?", Goods.class, 20);
        System.out.println(goods1);


        int update = goodsDao.update("insert into goods values (?,?,?)",30, "vovo手机",2500);
        System.out.println(update > 0 ? "成功" : "未修改表");


        int update1 = goodsDao.update("delete from goods where id = ?", 20);
        System.out.println(update1 > 0 ? "成功" : "未修改表");
    }
    
}
